//
//  KABillListTip.swift
//  kano
//
//  Created by Frank on 2024/9/18.
//

import UIKit
import ActiveLabel

class KABillListTip: UIView {
    
    var handler: (()->())?
    
    
    lazy var tipTitle: ActiveLabel = {
        tipTitle = ActiveLabel()
        let customType = ActiveType.custom(pattern: "overdue charges")
        tipTitle.enabledTypes = [customType]
        tipTitle.numberOfLines = 0
        tipTitle.text = "LendSafe Overdue users credit information will be duly reported according to regulations. Please repay on time to avoid incurring overdue charges and creating a bad credit | record for yourself."
        //tipTitle.lineSpacing = kscale(8)
        tipTitle.font = UIFont.systemFont(ofSize: kscale(11), weight: .medium)
        tipTitle.customColor[customType] = .themeColor
        tipTitle.textColor = .colorFF5B42
        tipTitle.handleCustomTap(for: customType, handler: { [self] (customType) in
            if handler != nil {
                handler!()
            }
        })
        return tipTitle
    }()
    
    
    lazy var var_bgView: UIView = {
        let var_bgView = UIView()
        var_bgView.backgroundColor = .colorFFD0BF
        var_bgView.layer.cornerRadius = 10
        var_bgView.layer.masksToBounds = true
        return var_bgView
    }()
    
    init() {
        super.init(frame: CGRectMake(0, 0, var_screenWidth, kscale(76)))
        let maxSize = CGSize(width: var_screenWidth-kscale(44), height: .greatestFiniteMagnitude)
        let tipLabelH = tipTitle.sizeThatFits(maxSize).height
        self.height = tipLabelH + kscale(44)
        
        ka_setUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func ka_setUI() {
        backgroundColor = .white
        addSubview(var_bgView)
        addSubview(tipTitle)
        
        var_bgView.snp.makeConstraints { make in
            make.left.top.equalTo(kscale(12))
            make.bottom.right.equalTo(kscale(-12))
        }
        tipTitle.snp.makeConstraints { make in
            make.left.top.equalTo(kscale(22))
            make.bottom.right.equalTo(kscale(-22))
        }
    }
}
